#
# @lc app=leetcode.cn id=1014 lang=python3
#
# [1014] 最佳观光组合
#

# @lc code=start
from typing import List


class Solution:
    def maxScoreSightseeingPair(self, values: List[int]) -> int:
        #values[i] + i - (j - values[j])
        x = values[0]
        n = len(values)
        ans = 0
        for i in range(1,n):
            ans = max(ans,x - (i - values[i]))
            x = max(x,i + values[i])
        return ans
# @lc code=end

